<?php

use think\migration\Migrator;
use think\migration\db\Column;

class CreateShopActivityGiftTable extends Migrator
{
    /**
     * Migrate Up.
     */
    public function up()
    {
        $table = $this->table('shop_activity_gift_log', ['comment' => '满赠记录', 'engine' => 'InnoDB', 'collation' => 'utf8mb4_general_ci']);
        $table->addColumn('activity_id', 'integer', ['limit' =>  11, 'default' => 0, 'comment' => '活动'])
            ->addColumn('order_id', 'integer', ['limit' =>  11, 'default' => 0, 'comment' => '订单'])
            ->addColumn('user_id', 'integer', ['limit' =>  11, 'default' => 0, 'comment' => '用户'])
            ->addColumn(Column::enum('type', ['coupon', 'score', 'money', 'goods'])->setNull(true)->setDefault(null)->setComment('礼品类型:coupon=优惠券,score=积分,money=余额,goods=商品'))
            ->addColumn('gift', 'string', ['limit' => 60, 'null' => true, 'default' => null, 'comment' => '礼品'])
            ->addColumn('value', 'string', ['limit' => 60, 'null' => true, 'default' => null, 'comment' => '价值'])
            ->addColumn('rules', 'string', ['limit' => 2048, 'null' => true, 'default' => null, 'comment' => '规则'])
            ->addColumn(Column::enum('status', ['waiting', 'finish', 'fail'])->setNull(true)->setDefault('waiting')->setComment('状态:waiting=等待赠送,finish=赠送完成,fail=赠送失败'))
            ->addColumn('fail_msg', 'string', ['limit' => 255, 'null' => true, 'default' => null, 'comment' => '赠送失败原因'])
            ->addColumn('errors', 'string', ['limit' => 1024, 'null' => true, 'default' => null, 'comment' => '具体原因'])
            ->addColumn('create_time', 'integer', ['limit'  =>  10, 'null' => true, 'default' => null, 'comment' => '创建时间'])
            ->addColumn('update_time', 'integer', ['limit'  => 10, 'null' => true, 'default' => null, 'comment' => '更新时间'])
            ->addIndex('order_id')
            ->addIndex('user_id')
            ->create();
    }

    /**
     * Migrate Down.
     */
    public function down()
    {
        $table = $this->table('shop_activity_gift_log');
        $table->drop();
    }
}
